﻿using Hangfire;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.Uow;

namespace Demo.HangfireIntergation.Jobs
{
    public class MyLogWorker : HangfireBackgroundWorkerBase
    {
        public MyLogWorker()
        {
            RecurringJobId = nameof(MyLogWorker);
            //执行周期每分钟执行
            CronExpression = Cron.MinuteInterval(1);
        }
        /// <summary>
        /// 执行任务
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override Task DoWorkAsync(CancellationToken cancellationToken = default)
        {
            using (var uow = LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>().Begin())
            {
                Logger.LogInformation("定时任务执行... MyLogWorker..!");
                return Task.CompletedTask;
            }
        }
    }
}
